package com.example.demo.repository;

import com.example.demo.LogUtil;
import com.normalClasses.eye.*;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.mail.internet.MimeMessage;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Repository;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import freemarker.template.Template;

@Slf4j
@Repository
public class CustomerRepository implements AutoMessageHandler {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public String Auto_time_warning(String cookie) {
        // TODO Auto-generated method stub
        String usernameString = this.Auto_getusername(cookie);
        if (usernameString != null) {
            List user1 = (List) jdbcTemplate.queryForList("select logout_time from t_people_logout_time where `username` = '" + usernameString + "' and `recent_bit` = 0");
            List user2 = (List) jdbcTemplate.queryForList("select login_time  from t_people_login_time where `username` = '" + usernameString + "' and `recent_bit` = 0");
            String timeout = "";
            String timelogin = "";
            if (user1.size() > 0 && user2.size() > 0) {
                Map tip1 = (Map) user1.get(0);
                Map tip2 = (Map) user2.get(0);
                timeout = (String) tip1.get("logout_time");
                timelogin = (String) tip2.get("login_time");
                timeout = timeout.substring(0, 10);
                timelogin = timelogin.substring(0, 10);
                Time time = new Time();
                message message = new message();
                message.setTitle("新提示");
                message.setContent("您距上次的学习的时间已有" + time.time(Long.parseLong(timelogin), Long.parseLong(timeout)));
                String msg = JSON.toJSONString(message);
                return msg;
            } else if (user1.size() == 0) {
                message message = new message();
                message.setTitle("新提示");
                message.setContent("欢迎您的来临，眼视科技伴您时光！");
                String msg = JSON.toJSONString(message);
                return msg;
            } else {
                message message = new message();
                message.setTitle("新提示");
                message.setContent("身份信息存在异常，我们后续会为您进行处理");
                log.error(LogUtil.logSpec("this " + cookie + "has something wrong with timelogin or timeout", 7));
                String msg = JSON.toJSONString(message);
                return msg;
            }
        } else {
            message message = new message();
            message.setTitle("新提示");
            message.setContent("未正确获取您的身份凭证，我们将会自动处理你的异常行为");
            String msg = JSON.toJSONString(message);
            log.error(LogUtil.logSpec("use Auto_time_warning error, this function can't use cookie to find username", 7));
            return msg;
        }
    }

    @Override
    public String Auto_weather_warning(String cookie) {
        // TODO Auto-generated method stub
        String usernameString = this.Auto_getusername(cookie);
        String ip = "";
        List user1 = (List) jdbcTemplate.queryForList("select ip from t_people_login_ips where `username` ='" + usernameString + "' order by `login_time` DESC limit 1");
        if (user1.size() > 0) {
            Map people = (Map) user1.get(0);
            ip = (String) people.get("ip");//通过username获得用户ip
            //本机测试时受到ip的影响，屏蔽掉测试ip
            if (ip.equals("127.0.0.1") || ip.equals("localhost")) {
                message message = new message();
                message.setTitle("当前使用的是测试模式");
                message.setContent("测试ip将会在网路访问模式被更改");
                String msg = JSON.toJSONString(message);
                return msg;
            }
        }
        IpLocation ipLocation = new IpLocation(ip);
        Weather weather = new Weather(ipLocation.get_city());
        JSONObject weatherJsonObject = weather.get_weather();
        //防止第三方服务访问超时做的异常处理
        if (weatherJsonObject == null) {
            message message = new message();
            message.setTitle("在我们访问第三方服务时超时了");
            message.setContent("非常抱歉，您的问题已经反馈给服务端，我们会尽快为您处理");
            log.info(LogUtil.logSpec(cookie + "use Auto_weather_warning,system has overtime problem"));
            String msg = JSON.toJSONString(message);
            return msg;
        } else {
            JSONObject resultJsonObject = weatherJsonObject.getJSONObject("result");
            JSONArray index = resultJsonObject.getJSONArray("index");
            JSONObject index3 = index.getJSONObject(3);
            message message = new message();
            message.setTitle("您的城市" + resultJsonObject.getString("city"));
            message.setContent(resultJsonObject.getString("week") + "!" + "今日最高气温" + resultJsonObject.getString("temp") + "度,最低温度" + resultJsonObject.getString("templow") + "度" + index3.getString("detail"));
            String msg = JSON.toJSONString(message);
            return msg;
        }

    }

    @Override
    public boolean Auto_check_onlinepeople() {
        // TODO Auto-generated method stub
        int onlinenumber = 0;
        List user = (List) jdbcTemplate.queryForList("select username from t_people_right_static");
        if (user.size() > 0) {
            for (int i = 0; i < user.size(); i++) {
                Map item = (Map) user.get(i);
                String username = (String) item.get("username");
                List user1 = (List) jdbcTemplate.queryForList("select logout_time from t_people_logout_time where `username`= '" + username + "' and `recent_bit`=0");
                List user2 = (List) jdbcTemplate.queryForList("select login_time from t_people_login_time where `username`= '" + username + "' and `recent_bit`=0");
                if (user1.size() > 0 && user2.size() > 0) {
                    Map item1 = (Map) user1.get(0);
                    Map item2 = (Map) user2.get(0);
                    String timeout = (String) item1.get("logout_time");
                    String timelogin = (String) item2.get("login_time");
                    timeout = timeout.substring(0, 10);
                    timelogin = timelogin.substring(0, 10);
                    if ((Long.parseLong(timeout) - Long.parseLong(timelogin)) < 0) {
                        onlinenumber++;
                    }
                } else continue;
            }
        } else return false;
        //当存在在线人数时候，返回正常值，降低对socket类的依赖
        if (onlinenumber > 0) return true;
        else return false;
    }

    @Override
    public boolean Auto_check_scheduleTask(String cookie) {
        // TODO Auto-generated method stub
        String usernameString = this.Auto_getusername(cookie);
        if (usernameString != null) {
            List user1 = (List) jdbcTemplate.queryForList("select * from t_people_message_hint where `username` ='" + usernameString + "' and `status` ='true'");
            if (user1.size() > 0) {
                return true;
            } else {
                log.info(LogUtil.logSpec(cookie + "does not have scheduleTask"));
                return false;
            }
        } else {
            log.error(LogUtil.logSpec("use Auto_check_scheduleTask, system has bug", 7));
            return false;
        }
    }

    @Override
    public boolean Auto_deposit_message(String cookie, String message, String status, int order, int priority) {
        // TODO Auto-generated method stub
        if (message == null || message == "") return false;
        String usernameString = this.Auto_getusername(cookie);
        if (usernameString != null) {
            jdbcTemplate.update("INSERT INTO `t_people_small_message`(`username`, `message`, `status`,`messageorder`,`priority`) VALUES (?,?,?,?,?)", usernameString, message, status, order, priority);
            return true;
        } else {
            log.error(LogUtil.logSpec("Auto_deposit_message to find username failed", 7));
            return false;
        }
    }

    @Override
    public String Auto_output_message(String cookie) {
        // TODO Auto-generated method stub
        String usernameString = this.Auto_getusername(cookie);
        List user1 = (List) jdbcTemplate.queryForList("select * from (select * from t_people_small_message where `status` ='true') AS newtable where `username` ='" + usernameString + "' and `messageorder`=(select MIN(`messageorder`) from (select * from t_people_small_message where `status` ='true') AS newtable ) and `priority`=(select MAX(`priority`)from (select * from t_people_small_message where `status` ='true') AS newtable )");
        if (user1.size() > 0) {
            Map people = (Map) user1.get(0);
            //System.out.println();
            return (String) people.get("message");
        } else return null;
    }

    @Override
    public void Auto_handle_readmessage(String message, String cookie) {
        // TODO Auto-generated method stub
        String usernameString = this.Auto_getusername(cookie);
        jdbcTemplate.update("UPDATE t_people_small_message set `status`='false' where `message`='" + message + "' and `status` ='true' and `username` ='" + usernameString + "'");
        log.info(LogUtil.logSpec("Auto_handle_readmessage performed a message destruction"));
    }

    @Override
    public void Auto_sign_maker(String cookie) {
        // TODO Auto-generated method stub
        String usernameString = this.Auto_getusername(cookie);
        jdbcTemplate.update("UPDATE t_people_message_hint set `status`='false' where `status`='true' and `username`='" + usernameString + "'");
        //进行权限更改，标记已经执行过一次
        log.info(LogUtil.logSpec(usernameString + " had changed once message permission"));
    }

    @Autowired
    private JavaMailSender mailSender;
    @Autowired
    private FreeMarkerConfigurer freemarker;

    @Override
    public void Auto_send_mail(String username) {
        // TODO Auto-generated method stub
        String usernameString = username;
        String mailString = "";
        List user = (List) jdbcTemplate.queryForList("select email from t_people_right_static where `username` ='" + usernameString + "'");
        if (user.size() > 0) {
            Map people = (Map) user.get(0);
            mailString = (String) people.get("email");
        }
        List user1 = (List) jdbcTemplate.queryForList("select * from t_people_small_message where `username` ='" + usernameString + "' and `status` ='true'");
        if (user1.size() > 0) {
            String msgString = "";
            //生成内容
            for (int i = 0; i < user1.size(); i++) {
                Map people = (Map) user1.get(i);
                JSONObject messJsonObject = JSON.parseObject((String) people.get("message"));
                msgString += i + ":" + messJsonObject.getString("content") + "。";
            }
            MimeMessage msg = mailSender.createMimeMessage();
            try {
                MimeMessageHelper helper = new MimeMessageHelper(msg, true);
                //静态赋值，不可更改
                helper.setFrom("1987477513@qq.com");
                helper.setTo(mailString);
                helper.setSubject("新的信息");
                //封装模板使用的数据
                Map<String, Object> modeMap = new HashMap<>();
                modeMap.put("maintext", msgString);
                //得到模板信息
                Template template = freemarker.getConfiguration().getTemplate("template.html");
                //转化字符串
                String htmlString = FreeMarkerTemplateUtils.processTemplateIntoString(template, modeMap);
                helper.setText(htmlString, true);
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
                log.warn(LogUtil.logSpec("Auto_send_mail has Exception"));
            }
            mailSender.send(msg);
            log.info(LogUtil.logSpec("send to " + mailString + "a notice email"));
            this.Auto_destroy_message(usernameString);
        } else log.info(LogUtil.logSpec("check" + usernameString + " message , do not "));

    }

    @Override
    public void Auto_destroy_message(String username) {
        // TODO Auto-generated method stub
        jdbcTemplate.update("UPDATE t_people_small_message set `status`='false' where `status`='true' and `username`='" + username + "'");
        log.info(LogUtil.logSpec(username + "use once Auto_destroy_message"));
    }

    @Override
    public String[] Auto_find_username() {
        // TODO Auto-generated method stub
        List user = (List) jdbcTemplate.queryForList("select username from t_people_right_static ");
        String username[] = new String[user.size()];
        for (int i = 0; i < user.size(); i++) {
            Map people = (Map) user.get(i);
            username[i] = (String) people.get("username");
        }
        return username;
    }

    @Override
    public String Auto_getusername(String cookie) {
        // TODO Auto-generated method stub
        List user = (List) jdbcTemplate.queryForList("select username from t_people_login_cookies where `cookies`='" + cookie + "'");
        if (user.size() > 0) {
            Map people = (Map) user.get(0);
            //System.out.println(people.get("username"));
            return (String) people.get("username");
        } else return null;
    }

    //之后修改
    @Override
    public void Auto_clean_mysql() {
        // TODO Auto-generated method stub
        //主检索
        List user = (List) jdbcTemplate.queryForList("select username from peopleright where `loginstatus` ='true'");
        //逐个检索数据库多余信息
        if (user.size() > 0) {
            for (int i = 0; i < user.size(); i++) {
                Map people = (Map) user.get(i);
                String username = (String) people.get("username");
                List user1 = (List) jdbcTemplate.queryForList("select * from peoplelogin where `status` ='false' and `username`='" + username + "'");
                if (user1.size() > 5) {
                    int number = user1.size() - 5;
                    jdbcTemplate.update("delete from peoplelogin where `status`='false' and `username`='" + username + "' limit " + number);
                }
                List user2 = (List) jdbcTemplate.queryForList("select * from peoplemessagemakehint where `status` ='false' and `username`='" + username + "'");
                if (user2.size() > 5) {
                    int number = user2.size() - 5;
                    jdbcTemplate.update("delete from peoplemessagemakehint where `status`='false' and `username`='" + username + "' limit " + number);
                }
                List user3 = (List) jdbcTemplate.queryForList("select * from peoplesocketmessage where `status` ='false' and `username`='" + username + "'");
                if (user3.size() > 30) {
                    int number = user3.size() - 30;
                    jdbcTemplate.update("delete from peoplesocketmessage where `status`='false' and `username`='" + username + "' limit " + number);
                }
                List user4 = (List) jdbcTemplate.queryForList("select * from peopletimeline where `status` ='false' and `username`='" + username + "'");
                if (user4.size() > 20) {
                    int number = user4.size() - 20;
                    jdbcTemplate.update("delete from peopletimeline where `status`='false' and `username`='" + username + "' limit " + number);
                }
                System.out.println("对" + username + "进行了一次清洗");
            }
        }

    }

    @Override
    public boolean Auto_check_nickname(String cookie) {
        // TODO Auto-generated method stub
        String username = Auto_getusername(cookie);
        if (username != null) {
            List user = (List) jdbcTemplate.queryForList("select nickname from t_people_right_static where `username` ='" + username + "'");
            Map people = (Map) user.get(0);
            String nickname = (String) people.get("nickname");
            if (nickname.equals("") == true) {
                return false;
            } else return true;
        } else {
            log.error(LogUtil.logSpec("use cookie to find username failed, system maybe has bug", 7));
            return false;
        }
    }

    @Override
    public void Auto_storage_nickname(String cookie, String nickname) {
        // TODO Auto-generated method stub
        String username = this.Auto_getusername(cookie);
        if (username != null) {
            //先用nickname查询url
            List user_nick = (List) jdbcTemplate.queryForList("select userimg from t_nickname_userimg where `nickname`='" + nickname + "'");
            if (user_nick.size() > 0) {
                Map userimg = (Map) user_nick.get(0);
                jdbcTemplate.update("UPDATE t_people_right_static set `userimg`='" + (String) userimg.get("userimg") + "', `nickname`='" + nickname + "' where `username` ='" + username + "'");
                jdbcTemplate.update("UPDATE t_nickname_userimg set `dirty_bit`= 1 where `nickname` ='" + nickname + "'");
                //触动消息制，基于socket连接时去提示
                List user = (List) jdbcTemplate.queryForList("select message from t_people_small_message where `status` ='true' and `priority`=1 and `username`='" + username + "'");
                message message = new message();
                message.setTitle("操作提示");
                message.setContent(nickname + "恭喜你，获得新的昵称和头像");
                String msg = JSON.toJSONString(message);
                this.Auto_deposit_message(cookie, msg, "true", user.size() + 1, 1);
            } else {
                log.warn(LogUtil.logSpec("Failed to query user name may be caused by cookie time failure or database failure", 9));
            }
        } else log.error(LogUtil.logSpec("use nickname to find urlimg failed ,maybe system has bug", 9));
    }

    //此方法可能弃用，之后讨论
    @Override
    public void Auto_handle_timeout_cookie() {
        // TODO Auto-generated method stub
        List user = (List) jdbcTemplate.queryForList("select cookie,time from peoplelogin where `status` ='true'");
        if (user.size() > 0) {
            for (int i = 0; i < user.size(); i++) {
                Map people = (Map) user.get(i);
                if ((long) (System.currentTimeMillis() / 1000) - Long.parseLong(((String) people.get("time")).substring(0, 10)) > 3 * 24 * 60 * 60) {
                    jdbcTemplate.update("UPDATE peoplelogin set `status`='false' where `cookie` ='" + (String) people.get("cookie") + "'");
                }
            }
            System.out.println("cookie检查模块正常执行！");
        }
    }

    //此方法暂时不考虑更改
    @Override
    public void Auto_handle_login_exception() {
        // TODO Auto-generated method stub
        List user = (List) jdbcTemplate.queryForList("select username from peopleright");
        if (user.size() > 0) {
            for (int i = 0; i < user.size(); i++) {
                Map item = (Map) user.get(i);
                String username = (String) item.get("username");
                List user1 = (List) jdbcTemplate.queryForList("select * from peopletimeline where `username`= '" + username + "' and `status`='true' and `pointtype`=0");
                List user2 = (List) jdbcTemplate.queryForList("select * from peopletimeline where `username`= '" + username + "' and `status`='true' and `pointtype`=1");
                if (user1.size() > 0 && user2.size() > 0) {
                    Map item1 = (Map) user1.get(0);
                    Map item2 = (Map) user2.get(0);
                    String timeout = (String) item1.get("timepoint");
                    String timelogin = (String) item2.get("timepoint");
                    timeout = timeout.substring(0, 10);
                    timelogin = timelogin.substring(0, 10);
                    if ((Long.parseLong(timeout) - Long.parseLong(timelogin)) < 0) {
                        jdbcTemplate.update("UPDATE peopletimeline set `timepoint` ='" + System.currentTimeMillis() + "' where `username`='" + username + "' and `pointtype` =0 and `status`='true'");
                        System.out.println("对" + username + "执行了登陆状态异常的维护！");
                    }
                } else continue;
            }
        }
    }

    @Override
    public String[] Auto_get_usercookie(String username) {
        // TODO Auto-generated method stub
        List user = (List) jdbcTemplate.queryForList("select cookies from t_people_login_cookies where `username` ='" + username + "'");
        if (user.size() > 0) {
            String[] res_cookieStrings = new String[user.size()];
            for (int i = 0; i < user.size(); i++) {
                Map res = (Map) user.get(i);
                res_cookieStrings[i] = (String) res.get("cookies");
            }
            return res_cookieStrings;
        }
        return null;
    }

    @Override
    public String[] Auto_get_userip(String username) {
        // TODO Auto-generated method stub
        List user = (List) jdbcTemplate.queryForList("select ip from t_people_login_ips where `username` ='" + username + "'");
        if (user.size() > 0) {
            String[] res_ipStrings = new String[user.size()];
            for (int i = 0; i < user.size(); i++) {
                Map res = (Map) user.get(i);
                res_ipStrings[i] = (String) res.get("ip");
            }
            return res_ipStrings;
        }
        return null;
    }

    @Override
    public String[] Auto_operation_notice(String cookie) {
        // TODO Auto-generated method stub
        //首先获取用户名
        String username = this.Auto_getusername(cookie);
        //如果获得不到用户名
        if (username == null) {
            log.error(LogUtil.logSpec("Auto_operation_notice has problem, system maybe has bug", 7));
            return null;
        }
        //查询用户新旧度
        List user = (List) jdbcTemplate.queryForList("select `dirty_bit` from `t_user_habit` where `username` ='" + username + "'");
        //获取用户的新旧度
        int bit = (int) ((Map) user.get(0)).get("dirty_bit");
        //判断新旧程度
        if (bit <= 5) {
            //添加提示内容
            ArrayList<String> msgArrayList = new ArrayList<>();
            message message = new message();
            message.setTitle("眼动操作说明");
            message.setContent("单眨右眼可以切换模式，普通->结点->阅读,如此循环");
            String msg = JSON.toJSONString(message);
            msgArrayList.add(msg);
            message.setTitle("眼动操作说明");
            message.setContent("单眨左眼可以点击，请闭眼时稍微用力即可");
            msg = JSON.toJSONString(message);
            msgArrayList.add(msg);
            message.setTitle("眼动操作说明");
            message.setContent("我们为头部的动作提供了丰富交互，可以自由活动摇摇头试试，或者前倾后退身体试试");
            msg = JSON.toJSONString(message);
            msgArrayList.add(msg);
            String[] res = (String[]) msgArrayList.toArray(new String[msgArrayList.size()]);
            //更新用户的新旧度
            jdbcTemplate.update("UPDATE `t_user_habit` set `dirty_bit` =" + (bit + 1) + " where `username` ='" + username + "'");
            return res;
        }
        return null;
    }

    public String Auto_feiyan_warning(String cookie) {
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub
        String usernameString = this.Auto_getusername(cookie);
        String ip = "";
        List user1 = (List) jdbcTemplate.queryForList("select ip from t_people_login_ips where `username` ='" + usernameString + "' order by `login_time` DESC limit 1");
        if (user1.size() > 0) {
            Map people = (Map) user1.get(0);
            ip = (String) people.get("ip");//通过username获得用户ip
            //本机测试时受到ip的影响，屏蔽掉测试ip
            if (ip.equals("127.0.0.1") || ip.equals("localhost")) {
                message message = new message();
                List user = (List) jdbcTemplate.queryForList("SELECT * FROM `t_feiyan` WHERE `name`='西安' ORDER BY UpdateTime DESC LIMIT 1");
                Map item = (Map) user.get(0);
                message.setTitle("当前使用的是测试模式");
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    message.setContent("测试模式的肺炎信息我们将不给予提供，建议您使用公网地址,http://yandongxunjing.club:8090/test2/hello.html" + "我们将只提供默认地点 最新的更新时间是" + simpleDateFormat.format(new Date(simpleDateFormat.parse(simpleDateFormat.format(item.get("UpdateTime"))).getTime() - 28800000)) + "您的省份/市是" + item.get("province") + "," + ((int) item.get("zero") > 0 ? "已经连续" + (int) item.get("zero") + "天无病例了," : "") + "今日确诊" + item.get("today_confirm") + "人，累计确诊" + item.get("total_confirm") + "人，治愈率" + item.get("total_healRate") + "%,死亡率" + item.get("total_deadRate") + "%,注意您的防护措施。");
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                String msg = JSON.toJSONString(message);
                return msg;
            }
        }
        IpLocation ipLocation = new IpLocation(ip);
        Weather weather = new Weather(ipLocation.get_city());
        JSONObject weatherJsonObject = weather.get_weather();
        //防止第三方服务访问超时做的异常处理
        if (weatherJsonObject == null) {
            message message = new message();
            message.setTitle("在我们访问第三方服务时超时了");
            message.setContent("非常抱歉，您的问题已经反馈给服务端，我们会尽快为您处理");
            log.info(LogUtil.logSpec(cookie + "use Auto_feiyan_warning,system has overtime problem"));
            String msg = JSON.toJSONString(message);
            return msg;
        } else {
            JSONObject resultJsonObject = weatherJsonObject.getJSONObject("result");
            message message = new message();
            String city = resultJsonObject.getString("city");
            List user = (List) jdbcTemplate.queryForList("SELECT * FROM `t_feiyan` WHERE `name`='" + city + "' ORDER BY UpdateTime DESC LIMIT 1");
            if (user.size() > 0) {
                Map item = (Map) user.get(0);
                message.setTitle("当前城市疫情状况");
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    message.setContent("最新的更新时间是" + simpleDateFormat.format(new Date(simpleDateFormat.parse(simpleDateFormat.format((Timestamp) item.get("UpdateTime"))).getTime() - 28800000)) + "您的省份/市是" + item.get("province") + "," + ((int) item.get("zero") > 0 ? "已经连续" + (int) item.get("zero") + "天无病例了," : "") + "今日确诊" + item.get("today_confirm") + "人，累计确诊" + item.get("total_confirm") + "人，治愈率" + item.get("total_healRate") + "%,死亡率" + item.get("total_deadRate") + "%,注意您的防护措施。");
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                String msg = JSON.toJSONString(message);
                return msg;
            }
        }
        return null;

    }
}
